using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Authorization.Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Vue.H5.Authorization
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {

                    webBuilder.ConfigureKestrel(option =>
                    {
                        if (ConfigurationManage.GetEnvironmentName() == Environments.Development)
                        {
                            option.Listen(IPAddress.Any, 5000);
                        }
                        else
                        {
                            option.Listen(IPAddress.Any, 443, listenOptions =>
                            {
                                listenOptions.UseHttps(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManage.GetValue("HttpsConfig:FileName", false)), ConfigurationManage.GetValue("HttpsConfig:Password", false));
                            });
                        }
                    });

                    webBuilder.UseStartup<Startup>();
                });
    }
}
